package com.dailyblue.java.net.tcp.demo3;

import lombok.SneakyThrows;

import java.io.OutputStream;
import java.util.Scanner;

public class 写入 extends Thread {

    private OutputStream out;
    private String type;
    private Scanner scan;

    public 写入(OutputStream out, String type) {
        this.out = out;
        this.type = type;
        scan = new Scanner(System.in);
    }

    @SneakyThrows
    public void run() {
        while (true) {
            String message = scan.next();
            if ("exit".equals(message)) {
                break;
            }
            // 发送给对象
            out.write((type + message + "\n").getBytes());
        }
    }
}
